package com.honey.compilation.sql.ddl;

import com.honey.compilation.sql.SqlKeyWord;
import com.honey.compilation.sql.SqlScript;
import com.honey.compilation.sql.ValueElement;
import com.honey.core.builder.CharacterBuilder;
import com.honey.core.builder.CharacterBuilderFactory;
import com.honey.core.compiler.CompilationException;

/**
 * 删除数据库,非SQL 92定义
 * 
 * @author Administrator
 *
 */
@Deprecated
public class DropDatabase  extends  Drop implements SqlScript {
	
	private ValueElement databaseName ;
	
	private boolean exists = true;
	
	public DropDatabase(String databaseName){
		this.databaseName =new ValueElement( databaseName );
	}
	
	/**
	 * 是否添加判断语句( if exists)
	 * @return true:是  false:否
	 */
	public boolean isExists() {
		return exists;
	}

	/**
	 * 是否添加判断语句( if exists)
	 * @param exists  true:是  false:否
	 */
	public void setExists(boolean exists) {
		this.exists = exists;
	}

	/*
	 * (non-Javadoc)
	 * @see com.honey.core.dom.sql.ddl.Drop#compiledContent(int)
	 */
	@Override
	public CharacterBuilder compiledContent(int indentLevel ) throws CompilationException {
		CharacterBuilder answer = CharacterBuilderFactory.createC16StringBuilder();
	
		answer.append( super.compiledContent( indentLevel ) );
		answer.append(SqlKeyWord.DATABASE);
		if ( exists )
			answer.append(SqlKeyWord.IF).append( SqlKeyWord.EXISTS ) ;
		answer.append( databaseName );
		answer.append( SqlKeyWord.OPERATION_SEMICOLON );
		return answer;
	}
}
